import { Link } from '@brillout/docpress'
import { ConfigSpec } from '../../components'

<ConfigSpec
  env="config (build-time)"
  global={null}
>
```ts ts-only hide-menu
type Prerender = boolean | {
  partial?: boolean
  redirects?: boolean
  noExtraDir?: boolean
  parallel?: boolean | number
  disableAutoRun?: boolean
  enable?: null | boolean
  keepDistServer?: boolean
}
```
</ConfigSpec>

> <Link href="/pre-rendering" /> explains what pre-rendering is and how to use it.

The default values:

```ts
// pages/+config.ts

import type { Config } from 'vike/types'

export default {
  // The default values
  prerender: {
    partial: false,
    redirects: isFullyPrerendered, // Default value is true if all pages are pre-rendered
    noExtraDir: false,
    parallel: os.cpus.length, // Number of CPUs
    disableAutoRun: false,
    enable: true,
    keepDistServer: false
  }
} satisfies Config
```



## `partial`

`boolean` (default: `false`)

Stop showing a warning when pages cannot be pre-rendered.

> Vike shows a warning when a page has a parameterized route (e.g. <Link text="Route String" href="/route-string" /> `/movie/@movieId`) while there isn't any <Link text={<><code>onBeforePrerenderStart()</code> hook</>} href="/onBeforePrerenderStart" /> that provides at least one URL matching the page's route (e.g. `/movie/42`).
This setting doesn't affect the pre-rendering process: it only suppresses the warning.

Alternatively, set `+prerender` to `false` for the pages that cannot be pre-rendered — this also suppresses the warning. See <Link href="/pre-rendering#partial" />.

> As explained in <Link href="/pre-rendering" />, if you don't pre-render *all* your pages then you need a production server.
>
> That said, if you cannot or don't want to pre-render all your pages while still deploying to a <Link href="/static-hosts">static host</Link>, then see the workaround at [#1476 - Pre-rendered dynamic routes (static host deployment)](https://github.com/vikejs/vike/issues/1476).
>
> With <Link text={<code>vite-plugin-vercel</code>} href="/vercel#vite-plugin-vercel" />, you can statically deploy your pre-rendered pages while using a production server for your non-pre-rendered pages.


## `redirects`

`boolean` (default: `true` if the app is fully-prerendered)

Whether <Link href="/redirects">`+redirects`</Link> should be pre-rendered to following HTML:

```html
<!-- HTML redirecting user to /some/path -->
<html>
<head>
  <!-- Tell browser to redirect user -->
  <meta http-equiv="refresh" content="0;url=/some/path">
</head>
<body></body>
</html>
```


## `noExtraDir`

`boolean` (default: `false`)

Don't create a new directory for each HTML file.

For example, generate `dist/client/about.html` instead of `dist/client/about/index.html`.

> Generating a directory for each HTML file is the most reliable way for telling Static Hosts the static URL of each static HTML.
> But some static hosts prefer the other way.


## `parallel`

`boolean | number` (default: [`os.cpus().length`](https://nodejs.org/api/os.html#os_os_cpus))

Number of concurrent pre-render jobs.

Set to `false` (or `1`) to disable concurrency.

> The default value is the fastest, but it may induce high spikes of memory usage.
>
> Disable concurrency if:
> - You encounter `JavaScript heap out of memory` errors.
> - If pre-rendering takes an abnormal high amount of time. (Caused by the very slow process of memory swapping that kicks-in when memory starts to saturate).


## `disableAutoRun`

`boolean` (default: `false`)

When running `$ vike build`, Vike automatically triggers <Link href="/pre-rendering">pre-rendering</Link>. (If you <Link text="enabled it" href="/pre-rendering#get-started" />.)

You can disable the automatic triggering:

```ts
// pages/+config.ts

import type { Config } from 'vike/types'

export default {
  prerender: {
    // Stop `$ vike build` from initiating pre-rendering
    disableAutoRun: true
  }
} satisfies Config
```

You can then manually trigger pre-rendering using:
 - <Link href="/cli" />
 - <Link href="/api#prerender" doNotInferSectionTitle />


## `enable`

`boolean | null` (default: `true`)

When you set `prerender` to an object then you also enable pre-rendering. In other words:

```ts
// pages/+config.ts

import type { Config } from 'vike/types'

export default {
  // Setting it to an empty object:
  prerender: {},
  // Is equivalent to:
  prerender: true
} satisfies Config
```

By setting `prerender.enable` to `null` you opt-out from this. In other words:

```ts
// pages/+config.ts

import type { Config } from 'vike/types'

export default {
  // This:
  prerender: { enable: null },
  // Is equivalent to:
  prerender: null
} satisfies Config
```

This is useful, for example, if you want pre-rendering to stay opt-in instead of opt-out while setting pre-render settings globally.

It's also often used by <Link href="/extensions">Vike extensions</Link> to change pre-rendering settings without enabling pre-rendering on behalf of the user.

```js
// node_modules/some-vike-extension/+config.js

export default {
  prerender: {
    // Change pre-rendering setting:
    partial: true,
    // Without enabling pre-rendering:
    enable: null
  }
}
```

## `keepDistServer`

`boolean` (default: `false`)

If you pre-render all your pages (i.e. you didn't set <Link href="#partial">`partial`</Link> to `true`) then Vike removes the `dist/server/` directory (or `path.join(build.outDir, 'server/')` if you changed [`build.outDir`](https://vitejs.dev/config/build-options.html#build-outdir)) after pre-rendering has finished.

If you set `prerender.keepDistServer` to `true` then Vike won't remove the `dist/server/` directory.


## See also

- <Link href="/pre-rendering" />
- <Link href="/api#prerender" doNotInferSectionTitle />
- <Link href="/ssr" />
- <Link href="/stream" />
- <Link href="/streaming" />
- <Link href="/settings" />
